package com.yuwei.common.dialog

import android.content.Context
import android.content.DialogInterface
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.WindowManager
import android.widget.ImageView
import androidx.appcompat.app.AppCompatDialog
import com.blankj.utilcode.util.ToastUtils
import com.yuwei.common.R

/**
 * App更新对话框
 */
class AppUpdateDialog: AppCompatDialog {
    constructor(context: Context): super(context)
    constructor(context: Context, themeResId: Int): super(context, themeResId)
    constructor(context: Context, cancelable: Boolean, cancelListener: DialogInterface.OnCancelListener?): super(context, cancelable, cancelListener)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //加载布局
        setContentView(R.layout.app_update_dialog_layout)
        findViewById<ImageView>(R.id.iv_update_img)?.setOnClickListener {
            ToastUtils.showShort("点击了更新")
            cancel()
        }
        //取消事件
        findViewById<ImageView>(R.id.iv_update_close)?.setOnClickListener{
            cancel()
        }
        var windowParams: WindowManager.LayoutParams = window?.attributes!!
        windowParams.apply {
            dimAmount = 0.3f //设置灰暗度
            width = WindowManager.LayoutParams.MATCH_PARENT
            height = WindowManager.LayoutParams.MATCH_PARENT
        }
        window?.attributes = windowParams
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        setCancelable(true)
        setCanceledOnTouchOutside(false)
    }
}